#include "node.h"

Node::Node():
    isVaild(false),
    m_address(""),
    m_parentAdress(""),
    m_name(0),
    m_description(NODEFINE),
    m_Devdescribe(""),
    isActive(true),
    isTest(false),
    m_weight(0)


{
}
const QString &Node::getAddress() const
{
    return m_address;
}
void Node::setAddress(const QString &ad)
{
    m_address = ad;
}
//const QString &Node::getIEEE() const
//{
//    return m_IEEE;
//}
//void Node::setIEEE(const QString &ie)
//{
//    m_IEEE = ie;
//}
const QString &Node::getParentAd() const
{
    return m_parentAdress;
}
void Node::setParentAd(const QString &pa)
{
    m_parentAdress = pa;
}
//const QString& Node::getParentIEEE() const
//{
//    return m_parentIEEE;
//}
//void Node::setParentIEEE(const QString &paie)
//{
//    m_parentIEEE = paie;
//}
ushort Node::getName() const
{
    return m_name;
}

void Node::setName(ushort na)
{
    m_name = na;
}
NodeType Node::getDescription() const
{
    return m_description;
}

const QString& Node::getDevDescription() const
{
    return m_Devdescribe;
}
void Node::setDevDescription(const QString &des)
{
    m_Devdescribe = des;
}
void Node::setDescription(NodeType type)
{
    m_description = type;
}
bool Node::getState() const
{
    return isActive;
}
QByteArray Node::getCMD(quint8 cmdC) const
{
    QByteArray cmd;
    //    char temp[5];
    //    int len = Node::itoa(m_address,temp,5);
    //    cmd.append(temp,len);
    //    cmd.append(cmdC);
    cmd.append(m_address);
    cmd.append(cmdC);
    return cmd;

}
QByteArray Node::getCMDIEEE(quint8 /*cmdc*/) const
{
    QByteArray cmd;
    return cmd;

}
int Node::itoa(int val, char *buf,int size)//16进制
{
    char *p = buf;
    int len = 0;
    int slen = size;
    while(val > 0 && len < slen) {
        char t;
        t = val % 16;
        val -= t;
        val /= 16;
        if (t > 9) {
            *p++ = t- 10 + 'a';
        } else {
            *p++ = t + '0';
        }
        ++len;
    }
    for (int i = 0;i < len/2;++i) {
        char c = buf[i];
        buf[i] = buf[len-1-i];
        buf[len-1-i] = c;
    }
    buf[len] = '\0';
    return len;
}
bool Node::operator ==(const Node &o)
{
    return this->getAddress() == o.getAddress() && this->getName() == o.getName();

}

const QString Node::getFlagInfo(int flag)
{
    QString s;
    switch (flag) {
    case 1:
        s = QObject::trUtf8("温度");
        break;
    default:
        break;
    }
    return s;
}






